package com.wzh.yuvwater.utils;

/**
 * 时间等待工具类
 */
public class TimeWhere {
    private long startTime; //起始时间
    private long timeMillis; //结束时间

    /**
     * 开始执行
     *
     * @param timeMillis 等待多久结束
     * @return
     */
    public static TimeWhere start(long timeMillis) {
        TimeWhere timeUtils = new TimeWhere();
        timeUtils.startTime = System.currentTimeMillis(); //起始时间
        timeUtils.timeMillis = timeMillis;
        return timeUtils;
    }

    /**
     * 是否已经到达时间
     *
     * @return
     */
    public boolean isEnd() {
        long nowMillis = System.currentTimeMillis(); //起始时间
        return nowMillis - startTime > timeMillis;
    }

    /**
     * 重新开始
     *
     * @return 是否重新开始成功
     */
    public boolean reStart() {
        if (isEnd()) {
            this.startTime = System.currentTimeMillis();
            return true;
        }
        return false;
    }

}
